<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base target="${cxt }/">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>修改密码</title>

<link href="css/personalcenter/changepassword.css" rel="stylesheet"
	type="text/css" />
<script src="js/index/jquery-2.1.3.min.js"></script>
<script type="text/javascript">





	function change() {
		
		var msg = $("#error");
		var upwd=$("#pwdd").val();
		
		var pwd1 = $("input[name=pwd1]").val();
		var pwd2 = $("input[name=pwd2]").val();
		var pwd3 = $("input[name=pwd3]").val();

		if ($("input[name=pwd1]").val() == null
				|| $("input[name=pwd1]").val() == "") {
			alert("原密码不能为空");  //修改错误提示信息
			$("input[name=pwd1]").focus();
			return;
		}
		
		if ($("input[name=pwd1]").val() 
				!= $("#pwdd").val()) {
			alert("原密码输入错误");  //修改错误提示信息
			
			$("input[name=pwd1]").focus();
			return;
		}
		
		
		if ($("input[name=pwd2]").val() == null
				|| $("input[name=pwd2]").val() == "") {
			alert("新密码不能为空"); 
			$("input[name='pwd2']").focus();
			return;
		} 
		
		if ($("input[name=pwd2]").val().length<6)
				 {
			alert("用户密码不可以小于6位");  //修改错误提示信息
			$("input[name=pwd2]").focus();
			return;
		}
		
		 if ($("input[name='pwd3']").val() == null
				|| $("input[name='pwd3']").val() == "") {
			 alert("确认密码不能为空"); 
			$("input[name='pwd3']").focus();
			return;
		}
		
		if ($("input[name='pwd1']").val() == $("input[name='pwd2']")
				.val()) {
			alert("新密码不能与原密码相同"); 
			$("input[name='pwd2']").focus();
			return;
		} 
		 if ($("input[name='pwd2']").val() != $("input[name='pwd3']")
				.val()) {
			 alert("两次输入密码不一致"); 
			$("input[name='pwd3']").focus();
			return;
		}
		
		 $.ajax({
				url:"cpwd",
				type:"post",
				data:{pwd3:$("input[name='pwd3']").val()},
				datatype:"json",
				success:function(e){
				
				 alert(JSON.stringify(e));
				 if (e!="修改失败") {
					location.href="exitservlet";
				}
				 $("input[name='pwd1']").focus();
				$("input[name='pwd1']").val("");
				$("input[name='pwd2']").val("");
				$("input[name='pwd3']").val("");
				
				}
		 
	});
	

}	
</script>

</head>

<body>


	<div class="wrap_right">
		<form method="post" action="cpwd" id="YZfrom">
			<input id="pwdd" value="${user.password}" style="display:none;"/>

			<div class="wrap_right1">
				<span>修改密码</span>
				<span id="error" style="margin-left:300px;color:red;">${msg}</span>
			</div>
			<div class="wrap_right2">
				<ul>
					<li><span>旧密码:</span>
						<div class="wrap_right2_div">
							<input class="wrap_right2_input" name="pwd1" id="p1" type="password"/>
						
						</div></li>


					<li><span>新密码:</span>
						<div class="wrap_right2_div">
							<input class="wrap_right2_input" name="pwd2" type="password"/>
							
						</div></li>


					<li><span>确认密码:</span>
						<div class="wrap_right2_div">
							<input class="wrap_right2_input" name="pwd3" type="password"/>
						</div></li>


					<li><input type="button" id="btn" onclick="change()" value="保存" /></li>

				</ul>
			</div>

		</form>

	</div>

</body>
</html>